import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import { CakeVO, CakeForm, CakeQuery, material,CakeConfigType, cakeDefaultConfigQuery} from '@/api/sj/cake/types';

export const materialAccessory = (id: string): AxiosPromise<material> => {
  return request({
    url: `/sj/cakeMaterial/getTreeById/${id}`,
    method: 'get'
  });
};

export const cakeMaterial = (): AxiosPromise<material[]> => {
  return request({
    url: '/sj/cakeMaterial/list',
    method: 'get'
  });
};

/**
 * 查询蛋糕类型列表
 * @param query
 * @returns {*}
 */

export const listCake = (query?: CakeQuery): AxiosPromise<CakeVO[]> => {
  return request({
    url: '/sj/cake/list',
    method: 'get',
    params: query
  });
};

/**
 * 查询蛋糕类型详细
 * @param id
 */
export const getCake = (id: string | number): AxiosPromise<CakeVO> => {
  return request({
    url: '/sj/cake/' + id,
    method: 'get'
  });
};

/**
 * 新增蛋糕类型
 * @param data
 */
export const addCake = (data: CakeForm) => {
  return request({
    url: '/sj/cake',
    method: 'post',
    data: data
  });
};

/**
 * 修改蛋糕类型
 * @param data
 */
export const updateCake = (data: CakeForm) => {
  return request({
    url: '/sj/cake',
    method: 'put',
    data: data
  });
};

/**
 * 删除蛋糕类型
 * @param id
 */
export const delCake = (id: string | number | Array<string | number>) => {
  return request({
    url: '/sj/cake/' + id,
    method: 'delete'
  });
};

/**
 * 获得蛋糕盒默认配置
 * @param id
 */
export const getDefaultCakeConfig = (params:cakeDefaultConfigQuery) => {
  return request({
    url: '/system/cakeDefaultComposition/getDefaultByCakeId',
    method: 'get',
    params: params
  });
};

/**
 * 配置蛋糕盒配置
 * 
 */

export const setCakeConfig = (data:CakeConfigType)=>{
  return request({
    url: '/sj/cake/updateDefault',
    method: 'put',
    data: data
  })
};